package com.xuxk.project.library.util;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author  许孝康
 * @date 2019/7/2
 * @company 橙云科技有限公司
 */
public class PageInfoVo<T> implements Serializable {

    /**
     * 每页行数
     */
    private int pageSize;
    /**
     * 当前第几页
     */
    private int pageNum;
    /**
     * 总行数
     */
    private long total;
    /**
     * 数据集
     */
    private List<T> list;

    public PageInfoVo() {
    }

    public PageInfoVo(List<T> list)
    {
        if(list instanceof Page) {
            Page page = (Page)list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.list = page;
            this.total = page.getTotal();
        } else if(list instanceof Collection) {
            this.pageNum = 1;
            this.pageSize = list.size();
            this.list = list;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageInfoVo{" +
                "pageSize=" + pageSize +
                ", pageNum=" + pageNum +
                ", total=" + total +
                ", list=" + list +
                '}';
    }
}
